package homework.homework_6;

/**
 * @author 朱
 * @date 2019032818:56
 */

import java.util.Random;
import java.util.Scanner;

/**
 * 1、改进模拟登录
 * ,给三次机会,并提示还有几次（3次登录都失败，则提示账号被锁定）。如果登录成功，就可以玩猜数字小游戏了。
 */
public class EnterTest {
    public static void main(String[] args) {
        String USER="admin";
        String PASSWORD="admin";
        Scanner scannerString=new Scanner(System.in);
        Scanner scannerInt=new Scanner(System.in);
        System.out.println("请输入用户名：");
        String user=scannerString.nextLine();
        System.out.println("请输入密码");
        String password=scannerString.nextLine();
        for (int i = 2; i >0 ; i--) {
            if (user.equals(USER)&&password.equals(PASSWORD)){
                System.out.println("登录成功！");
                Random random=new Random();
                int r=random.nextInt(100);
                for (int j = 0; j <r ; j++) {
                    System.out.println("请输入您要猜的数据(1-100)");
                    int guess=scannerInt.nextInt();
                    if (guess==r){
                        System.out.println("恭喜你猜对了");
                        System.exit(0);
                    }else if (guess>r){
                        System.out.println("您猜的数组比随机数大");
                    }else if (guess<r){
                        System.out.println("您猜的数字比随机数小");
                    }
                }
            }else {
                System.out.println("登录失败，你还有"+i+"次机会");
                System.out.println("请输入用户名：");
                user=scannerString.nextLine();
                System.out.println("请输入密码");
                password=scannerString.nextLine();
            }
        }

    }
}
